package com.jinzecloud.reportapproval.controller;

import java.io.IOException;
import java.text.ParseException;
import java.util.Arrays;

import cn.hutool.extra.template.TemplateException;
import com.jinzecloud.reportapproval.bean.Report;
import com.jinzecloud.reportapproval.dto.Param;
import com.jinzecloud.reportapproval.enums.StateEnum;
import com.jinzecloud.reportapproval.service.ReportService;
import com.jinzecloud.reportapproval.service.TemperatureHumidityService;
import com.jinzecloud.reportapproval.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.jinzecloud.reportapproval.utils.PageUtils;
import com.jinzecloud.reportapproval.utils.R;
import org.springframework.web.multipart.MultipartFile;


/**
 * 检验报告
 *
 * @author æ­å°
 * @email 1971240051@qq.com
 * @date 2024-09-03 12:10:44
 */
@RestController
@RequestMapping("reportApproval/report")
@Api(tags = "检验报告", description = "检验报告", value = "检验报告")
public class ReportController {
    @Autowired
    private ReportService reportService;


    /**
     * 列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ApiOperation(value = "检验报告列表",notes = "检验报告列表")
    //@RequiresPermissions("reportApproval:report:list")
    public R list(@RequestBody Param param){
        PageUtils page = reportService.queryPage(param);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping(value = "/info/{id}",method = RequestMethod.POST)
    @ApiOperation(value = "检验报告信息",notes = "检验报告信息")
    //@RequiresPermissions("reportApproval:report:info")
    public R info(@PathVariable("id") Integer id){
		ReportVos report = reportService.getByIdReportVo(id);

        return R.ok().put("report", report);
    }

    /**
     * 信息
     */
    @RequestMapping(value = "/export/{id}",method = RequestMethod.POST)
    @ApiOperation(value = "检验报告信息",notes = "检验报告信息")
    //@RequiresPermissions("reportApproval:report:info")
    public R export(@PathVariable("id") Integer id){
        ReportExportVo report = reportService.getByIdReportExportVo(id);

        return R.ok().put("report", report);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ApiOperation(value = "检验报告保存",notes = "检验报告保存")
    //@RequiresPermissions("reportApproval:report:save")
    public R save(@RequestBody Report report){
		R r = reportService.saveReport(report);

        return r;
    }

    @RequestMapping(value = "/review",method = RequestMethod.POST)
    @ApiOperation(value = "检验报告审核",notes = "检验报告审核")
    //@RequiresPermissions("reportApproval:report:update")
    public R review(@RequestBody ReportVo reportVo){
        reportService.updateById(new Report().setId(reportVo.getId()).setReprotStatus(String.valueOf(0)));
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ApiOperation(value = "检验报告修改",notes = "检验报告修改")
    //@RequiresPermissions("reportApproval:report:update")
    public R update(@RequestBody ReportVo reportVo){
		reportService.updateByIdReportVo(reportVo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ApiOperation(value = "检验报告删除",notes = "检验报告删除")
    //@RequiresPermissions("reportApproval:report:delete")
    public R delete(@RequestBody Integer[] ids){
		reportService.removeByIdsReportVo(Arrays.asList(ids));

        return R.ok();
    }

    @ApiOperation("文件下载")
    @GetMapping("/fileUplod")
    public R fileDownload(String id) throws TemplateException, IllegalAccessException {
        String path = reportService.fileDownload(id);
        return R.ok().put("path", path);
    }
    @RequestMapping(value = "/checklist",method = RequestMethod.POST)
    @ApiOperation(value = "查询审批列表",notes = "查询审批列表")
    //@RequiresPermissions("reportApproval:productinfo:list")
    public R checklist(@RequestBody Param param){
        PageUtils page = reportService.queryPageCheckList(param);

        return R.ok().put("page", page);
    }
    @ApiOperation(value = "修改项目审批意见",notes = "修改项目审批意见", produces = "application/json")
    @PostMapping("/updateApprovalOpinion")
    //@RequiresPermissions("foundation:blapplyprojectinfo:update")
    public R updateApprovalOpinion(@RequestBody ReporteUpdateCheckVo reporteUpdateCheckVo){
        return reportService.updateApprovalOpinion(reporteUpdateCheckVo);
    }

    @ApiOperation("文件上传")
    @PostMapping("/fileUplod")
    public R fileUplod(String id, @RequestPart MultipartFile file) throws IOException {
        R r = reportService.fileUplod(id,file);
        return r;
    }

    @ApiOperation("查询文件路径")
    @GetMapping("/getReportFilePath/{id}")
    public R getReportFilePath(@PathVariable("id") String id) throws IOException, IllegalAccessException {
        String path = reportService.getReportFilePath(id);
        return R.ok().put("path", path);
    }

    @RequestMapping("/viewPdf/{id}")
    public String viewPdf(@PathVariable("id") Integer id){
        return reportService.viewPdf(id);
    }

    @RequestMapping("/viewWord/{id}")
    public String viewWord(@PathVariable("id") Integer id){
        return reportService.viewWord(id);
    }

}
